package com.hjm.ui.goods;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.hjm.ui.R;

public class GoodsStoreIntro extends LinearLayout {
    private ImageView storeImageView;
    private TextView storeNameTextView, storeAllNumTextView, storeNewNumTextView, storeFocusNumTextView;
    private ConstraintLayout storeIntroLayout;
    private Context context;
    public GoodsStoreIntro(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public GoodsStoreIntro(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GoodsStoreIntro);
        String storeName = a.getString(R.styleable.GoodsStoreIntro_storeNameText);
        Drawable storeImg = a.getDrawable(R.styleable.GoodsStoreIntro_storeImg);
        String storeAllNum = a.getString(R.styleable.GoodsStoreIntro_storeAllNumText);
        String storeNewNum = a.getString(R.styleable.GoodsStoreIntro_storeNewNumText);
        String storeFocusNum = a.getString(R.styleable.GoodsStoreIntro_storeFocusNumText);
        if(storeName!=null){
            storeNameTextView.setText(storeName);
        }
        if(storeImg!=null){
            storeImageView.setImageDrawable(storeImg);
        }
        if(storeAllNum!=null){
            storeAllNumTextView.setText(storeAllNum);
        }
        if(storeNewNum!=null){
            storeNewNumTextView.setText(storeNewNum);
        }
        if(storeFocusNum!=null){
            storeFocusNumTextView.setText(storeFocusNum);
        }
    }

    public GoodsStoreIntro(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        // 在这里添加你的布局和逻辑
        LayoutInflater.from(getContext()).inflate(R.layout.layout_goods_store_intro, this, true);
        storeImageView = findViewById(R.id.image_view_store_img);
        storeNameTextView = findViewById(R.id.text_view_store_name);
        storeAllNumTextView = findViewById(R.id.text_view_store_all_num);
        storeNewNumTextView = findViewById(R.id.text_view_store_new_num);
        storeFocusNumTextView = findViewById(R.id.text_view_store_focus_num);
        storeIntroLayout = findViewById(R.id.layout_goods_store_intro);
    }

    public void setStoreIcon(Bitmap bitmap){
        storeImageView.setImageBitmap(bitmap);
    }

    public void setStoreName(String storeName){
        storeNameTextView.setText(storeName);
    }

    public void setOnClickListener(OnClickListener listener){
        storeIntroLayout.setOnClickListener(listener);
    }
}
